#include "udpworkerthread.h"

UdpWorkerThread::UdpWorkerThread(QObject *parent) : QObject(parent) {
    thread = new QThread(this);
    worker = new UdpWorker();
    worker->moveToThread(thread);

    connect(thread, &QThread::finished, thread, &QThread::deleteLater);
}

UdpWorkerThread::~UdpWorkerThread() {
    stop();
    delete worker;
    delete thread;
}

void UdpWorkerThread::start() {
    thread->start();
}

void UdpWorkerThread::stop() {
    if (thread->isRunning()) {
        thread->quit();
        thread->wait();
    }
}

UdpWorker* UdpWorkerThread::getWorker() const {
    return worker;
}
